package com.mi.rof.rocketmq.comsumer;

/**
 * @author : Yang Yu you
 */

import com.mi.rof.engineer.service.RepairOrderStateService;
import com.mi.rof.entity.RepairOrder;
import com.mi.rof.entity.param.OrderParam;
import com.mi.rof.user.mapper.OrderTableMapper;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

import static com.mi.rof.utils.RocketMQTopic.SEND_ORDER_TOPIC;

@Component
@RocketMQMessageListener(consumerGroup = "consumer-group-order", topic = SEND_ORDER_TOPIC)
public class InsertOrderConsumer implements RocketMQListener<OrderParam> {
    @Resource
    private OrderTableMapper orderTableMapper;

    @Resource
    private RepairOrderStateService repairOrderStateService;

    @Override
    public void onMessage(OrderParam orderParam) {
        RepairOrder repairOrder = new RepairOrder();
        BeanUtils.copyProperties(orderParam, repairOrder);
        orderTableMapper.insert(repairOrder);
        repairOrderStateService.toPendingConfirm(repairOrder.getRepairOrderId());
    }
}
